package org.dromara.netbar.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.netbar.domain.vo.NetbarMemberLogVo;
import org.dromara.netbar.domain.bo.NetbarMemberLogBo;
import org.dromara.netbar.service.INetbarMemberLogService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 刷身份证记录
 *
 * @author Lion Li
 * @date 2025-06-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/netbar/memberLog")
public class NetbarMemberLogController extends BaseController {

    private final INetbarMemberLogService netbarMemberLogService;

    /**
     * 查询刷身份证记录列表
     */
    @SaCheckPermission("netbar:memberLog:list")
    @GetMapping("/list")
    public TableDataInfo<NetbarMemberLogVo> list(NetbarMemberLogBo bo, PageQuery pageQuery) {
        return netbarMemberLogService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出刷身份证记录列表
     */
    @SaCheckPermission("netbar:memberLog:export")
    @Log(title = "刷身份证记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NetbarMemberLogBo bo, HttpServletResponse response) {
        List<NetbarMemberLogVo> list = netbarMemberLogService.queryList(bo);
        ExcelUtil.exportExcel(list, "刷身份证记录", NetbarMemberLogVo.class, response);
    }

    /**
     * 获取刷身份证记录详细信息
     *
     * @param membetIdCardLog 主键
     */
    @SaCheckPermission("netbar:memberLog:query")
    @GetMapping("/{membetIdCardLog}")
    public R<NetbarMemberLogVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long membetIdCardLog) {
        return R.ok(netbarMemberLogService.queryById(membetIdCardLog));
    }

    /**
     * 新增刷身份证记录
     */
    @SaCheckPermission("netbar:memberLog:add")
    @Log(title = "刷身份证记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NetbarMemberLogBo bo) {
        return toAjax(netbarMemberLogService.insertByBo(bo));
    }

    /**
     * 修改刷身份证记录
     */
    @SaCheckPermission("netbar:memberLog:edit")
    @Log(title = "刷身份证记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NetbarMemberLogBo bo) {
        return toAjax(netbarMemberLogService.updateByBo(bo));
    }

    /**
     * 删除刷身份证记录
     *
     * @param membetCardLogIds 主键串
     */
    @SaCheckPermission("netbar:memberLog:remove")
    @Log(title = "刷身份证记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{membetCardLogIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] membetCardLogIds) {
        return toAjax(netbarMemberLogService.deleteWithValidByIds(List.of(membetCardLogIds), true));
    }
}
